package com.medical.goods.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.medical.goods.entity.*;
import com.medical.goods.entity.vo.OrderAuditVo;
import com.medical.goods.entity.vo.OrderDeliverVo;
import com.medical.goods.entity.vo.OrdercheckVo;
import com.medical.goods.entity.vo.OrderVo;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.medical.goods.service.OrderService;
import com.medical.common.utils.PageUtils;
import com.medical.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-08-13 20:42:37
 */
@RestController
@RequestMapping("goods/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    /*审核提交*/
    @RequestMapping("/submit")
    public void submit(@RequestParam(value = "id",defaultValue = "1")Integer id,
                       @RequestParam(value = "dispose",defaultValue = "1")Integer dispose,
                       @RequestParam(value = "remark",defaultValue = "")String remark
    ){
        orderService.submit(id,dispose,remark);
    }


    //订单审核页面
    @RequestMapping("/audit")
    public OrderAuditVo audit(@RequestParam("id")Integer id){
        return orderService.audit(id);
    }

    //订单发货页面
    @RequestMapping("/deliver")
    public void deliver(@RequestParam(value = "id",defaultValue = "1")Integer id,
                        @RequestParam(value = "logisticsName",defaultValue = "")String logisticsName,
                        @RequestParam(value = "logisticsOdd",defaultValue = "")String logisticsOdd,
                        @RequestParam(value = "logisiticsType",defaultValue = "")String logisiticsType,
                        @RequestParam(value = "logisticsPrice",defaultValue = "")String logisticsPrice,
                        @RequestParam(value = "logisticsRemark",defaultValue = "")String logisticsRemark
    ){
       orderService.deliver(id,logisticsName,logisticsOdd,logisiticsType,logisticsPrice,logisticsRemark);
    }

    /*
    * 订单查看页面*/
    @RequestMapping("/check/{id}")
    public OrdercheckVo check(@PathVariable("id") Integer id){
        return orderService.check(id);
    }

    /**
     * 订单列表
     */
    @RequestMapping("/orderlist")
    public List<OrderVo> orderList(@RequestBody OrderVo orderVo){
         return orderService.orderlist(orderVo);
    }

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = orderService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Integer id){
		OrderEntity order = orderService.getById(id);

        return R.ok().put("order", order);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody OrderEntity order){
		orderService.save(order);

        return R.ok();
    }

    /**
     * 支付完成后根据订单的coding修改订单状态
     */
    @RequestMapping("/update")
    public R update(@RequestBody OrderEntity order){
		orderService.update(order,new QueryWrapper<OrderEntity>().eq("order_coding",order.getOrderCoding()));
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Integer[] ids){
		orderService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
